package main

import (
	"fmt"

	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/region"
	cloudrtc "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cloudrtc/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cloudrtc/v2/model"
)

var ak = "<YOUR AK>"
var sk = "<YOUR SK>"
var endpoint = "<CloudRTC URL>"
var projectID = "<YOUR projectID>"
var regionInfo = "<RegionInfo>"

func createClient() (client *cloudrtc.CloudRTCClient) {
	auth := basic.NewCredentialsBuilder().
		WithProjectId(projectID).
		WithAk(ak).
		WithSk(sk).
		Build()

	client = cloudrtc.NewCloudRTCClient(
		cloudrtc.CloudRTCClientBuilder().
			WithRegion(region.NewRegion(regionInfo, endpoint)).
			WithCredential(auth).
			Build())
	return
}

func createApp() {
	client := createClient()

	appName := "<Your App Name>"
	req := &model.CreateAppRequest{
		Body: &model.AppReq{
			AppName: appName,
		},
	}
	response, err := client.CreateApp(req)
	if err == nil {
		fmt.Printf("%+v\n", response)
	} else {
		fmt.Println(err)
	}
}

func deleteApp() {
	client := createClient()
	req := &model.DeleteAppRequest{
		AppId: "<APPID>",
	}
	response, err := client.DeleteApp(req)
	if err == nil {
		fmt.Printf("%+v\n", response)
	} else {
		fmt.Println(err)
	}
}

func listApps() {
	client := createClient()

	state := model.GetListAppsRequestStateEnum().ACTIVATION
	var offset int32 = 0
	var limit int32 = 10
	req := &model.ListAppsRequest{
		State:  &state,
		Offset: &offset,
		Limit:  &limit,
	}

	response, err := client.ListApps(req)
	if err == nil {
		fmt.Printf("%+v\n", response)
	} else {
		fmt.Println(err)
	}
}

func showApp() {
	client := createClient()

	req := &model.ShowAppRequest{
		AppId: "<APPID>",
	}
	response, err := client.ShowApp(req)
	if err == nil {
		fmt.Printf("%+v\n", response)
	} else {
		fmt.Println(err)
	}
}
